define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/goods/index' + location.search,
                    // add_url: 'order/goods/add',
                    // edit_url: 'order/goods/edit',
                    // del_url: 'order/goods/del',
                    // multi_url: 'order/goods/multi',
                    // import_url: 'order/goods/import',
                    table: 'order_goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                visible: false,
                showToggle: false,
                showColumns: false,
                showExport: false,
                queryParams: function (params) {
                    var filter = JSON.parse(params.filter);
                    var op = JSON.parse(params.op);
                    var id = Fast.api.query('ids')
                    if (id) {
                        filter.order_id = id
                        op.order_id = '=';
                    }
                    params.filter = JSON.stringify(filter)
                    params.op = JSON.stringify(op)
                    return params;
                },
                
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'order_id', title: __('Order_id'),operate:false},
                        {field: 'goods_name', title: __('Goods_name'),operate:false},
                        // {field: 'goods_id', title: __('Goods_id')},
                        {field: 'goods_num', title: __('Goods_num'),operate:false},
                        {field: 'goods_price', title: __('Goods_price'), operate:false},
                        {field: 'total_price', title: __('Total_price'), operate:false},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
